package com.shopReduce.controller;

import java.text.ParseException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.shopReduce.bean.ReduceProgramme;
import com.shopReduce.bean.ShopReduce;
import com.shopReduce.service.IShopReduceService;

import shopBean.common.Enum.StatusAll;
import shopBean.common.bean.RestResult;
import shopBean.common.utils.RestResultGenerator;

@RestController
@RequestMapping("/shopReduce/")
public class ShopReduceContoller {

	
	@Autowired
	IShopReduceService shopReduceService;
	private static final Logger log = LoggerFactory.getLogger(ShopReduceContoller.class);
	
	@RequestMapping("/listManager.api")
	public RestResult list( @RequestBody ShopReduce shopReduce) {
		log.debug(shopReduce.toString());
		if(shopReduce.getStart() == null) {
			shopReduce.setStart(new Long(1));
		}
		if(shopReduce.getRow() == null) {
			shopReduce.setRow(new Long(10));
		}
		shopReduce.setStart((shopReduce.getStart()-1)*shopReduce.getRow());
		RestResult<List<ShopReduce>> result = RestResultGenerator.genSuccessResult(shopReduceService.list(shopReduce));
		result.setCount(shopReduceService.listCount(shopReduce));
		return result;
	}
	
	@RequestMapping("/deleteById.api")
	public RestResult deleteById(String id) {
		
		return this.shopReduceService.deleteById(id);
	}
	
	
	@RequestMapping("/updateById.api")
	public RestResult updateById( @RequestBody ShopReduce shopReduce) {
		
		
		return this.shopReduceService.updateById(shopReduce);
	}
	
	@RequestMapping("/insert.api")
	public RestResult insert( @RequestBody ShopReduce shopReduce) throws ParseException {
		return this.shopReduceService.insert(shopReduce);
	}
	
	
	@RequestMapping("/get")
	public RestResult<ShopReduce> get( String id) {
		return RestResultGenerator.genSuccessResult(this.shopReduceService.get(id));
	}
	
	@RequestMapping("/get.api")
	public RestResult<ShopReduce> getApi( String id) {
		return RestResultGenerator.genSuccessResult(this.shopReduceService.get(id));
	}
	
	
}
